<template>
  <div class="dialog_panel" @mouseleave="closeWindow" v-if="showWindow" :style="{ 'left':location.x + 'px', 'top': location.y + 'px' }">
    <div class="dialog_title">{{ title }}</div>
    <div class="dialog_content" @click="clickDialog">{{ dialogContent }}</div>
  </div>
</template>
<script>
export default {
  props: {
    title: {
      type: String,
      default() {
        return "提示标题"
      }
    }
  },
  data() {
    return {
      showWindow: false,
      dialogContent: "",
      location: { 
        x: null,
        y: null
      }
    };
  },
  methods: {
    openWindow(data = null, location = { x: null, y: null}) {// data->类型：string，显示弹框内容。location->类型：object，鼠标位置，显示弹框位置
      if (data) this.dialogContent = data; 
      if (location) this.location = location;
      this.showWindow = true;
    },
    closeWindow() {
      this.showWindow = false;
    },
    clickDialog() {
      this.$message({
        message: '您点击了弹框！',
        type: 'success'
      });
    }
  }
};
</script>

<style scoped>
.dialog_panel{
  position: fixed;
  z-index: 999;
  background-color: #ffffff;
  top: 0;
  left: 0;
  max-width: 150px;
  padding: 15px;
  border-radius: 5px;
  box-shadow: 0px 0px 5px gray;
}
.dialog_title {
  text-align: center;
  font-weight: bold;
}
.dialog_content {
  margin-top: 10px;
  color: #1890ff;
}
</style>
